﻿Public Class frmDangNhap
    Dim connect As New connect()
    Private Sub btnDangNhap_Click(sender As System.Object, e As System.EventArgs) Handles btnDangNhap.Click
        Dim tenDN = txtTenDangNhap.Text.Trim()
        Dim matKhau = txtMatKhau.Text.Trim()
        Dim dt As DataTable
        dt = connect.GetData("select * from NHANVIEN where TENDANGNHAP='" + tenDN + "' and MATKHAU='" + matKhau + "'")
        If (dt.Rows.Count() > 0) Then
            Dim maNV As String = dt.Rows(0)("MANV").ToString()
            Dim dt2 As New DataTable
            dt2 = connect.GetData("select distinct lnv.ROLE from NHANVIEN nv,LOAINHANVIEN lnv where nv.MALNV=lnv.MALNV and nv.TENDANGNHAP='" + tenDN + "'")
            Dim role As String = dt2.Rows(0)("ROLE").ToString()
            If (dt2.Rows.Count() > 0) Then
                frmQuanLy.ganTT(maNV, tenDN, role)
                MessageBox.Show("Đăng nhập thành công!")
                frmQuanLy.KiemTra()
                Me.Close()
            End If
        Else
            MessageBox.Show("Tên đăng nhập hoặc mật khẩu chưa đúng")
            txtTenDangNhap.Focus()
            Return
        End If
    End Sub


    Private Sub btnDong_Click(sender As System.Object, e As System.EventArgs) Handles btnDong.Click
        Me.Close()
    End Sub

    Private Sub frmDangNhap_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        If (e.KeyCode = Keys.Enter) Then
            btnDangNhap.PerformClick()
        End If
    End Sub

End Class